package com.example.ten.article;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.ten.R;
import com.example.ten.Utils.ContentUtils;
import com.example.ten.base.BaseFragment;
import com.google.gson.Gson;

/**
 * A simple {@link Fragment} subclass.
 */
public class ItemArticleFragment extends BaseFragment {
    TextView titleTv,authorTv1,timesTv,summaryTv,textTv,authorTv2,authorbriefTv;
    public ItemArticleFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_item_article, container, false);
        initView(view);

        Bundle bundle = getArguments();
        ArticleBean.ResultBean resultBean= (ArticleBean.ResultBean) bundle.getSerializable("article");
        titleTv.setText(resultBean.getTitle());
        summaryTv.setText(resultBean.getSummary());
        loadData(getContext(), ContentUtils.ARTICLE_DETATLS_URL+resultBean.getId(),
                "",false,true,true);
        return view;
    }

    private void initView(View view) {
        titleTv=view.findViewById(R.id.itemarcitle_tv_title);
        authorTv1=view.findViewById(R.id.itemarcitle_tv_author1);
        summaryTv=view.findViewById(R.id.itemarcitle_tv_summary);
        timesTv=view.findViewById(R.id.itemarcitle_tv_times);
        textTv=view.findViewById(R.id.itemarcitle_tv_text);
        authorTv2=view.findViewById(R.id.itemarticle_tv_author2);
        authorbriefTv = view.findViewById(R.id.itemarticle_tv_authorbrief);
    }

    @Override
    public void showDataFromNet(String s) {
        ArticleDetatlsBean articleDetatlsBean = new Gson().fromJson(s, ArticleDetatlsBean.class);
        String author = articleDetatlsBean.getAuthor();
        authorTv1.setText("作者:"+author);
        int times = articleDetatlsBean.getTimes();
        timesTv.setText("阅读量:"+String.valueOf(times));
        textTv.setText(articleDetatlsBean.getText());
        authorTv2.setText("作者:"+articleDetatlsBean.getAuthor());
        authorbriefTv.setText(articleDetatlsBean.getAuthorbrief());
    }
}
